/**
 * @Title: DishEmptyAdapter.java
 * @Project DCB
 * @Package com.pdw.dcb.ui.adapter
 * @Description: 沽清列表
 * @author zeng.ww
 * @date 2012-12-10 下午04:37:29
 * @version V1.0
 */
package com.netstar.ui.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.netstar.R;
import com.netstar.model.FlowSaveModel;
import com.netstar.util.StringUtil;

/**
 * Mtv适配器
 * 
 * @author zou.sq
 * @since 2013-03-12 下午04:37:29
 * @version 1.0
 */
public class FlowSaveAdapter extends BaseAdapter {
	private List<FlowSaveModel> mFlowSaveList;
	private Context mContext;
	private CallBack cb;

	/**
	 * 实例化对象
	 * 
	 * @param context
	 *            上下文
	 * @param dataList
	 *            数据列表
	 */
	public FlowSaveAdapter(Context context, List<FlowSaveModel> dataList, CallBack cb) {
		this.mContext = context;
		this.mFlowSaveList = dataList;
		this.cb = cb;
	}

	@Override
	public int getCount() {
		if (mFlowSaveList != null && !mFlowSaveList.isEmpty()) {
			return mFlowSaveList.size();
		}
		return 0;
	}

	@Override
	public FlowSaveModel getItem(int position) {
		if (mFlowSaveList != null) {
			return mFlowSaveList.get(position);
		}
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final FlowSaveModel model = mFlowSaveList.get(position);
		viewHode view = new viewHode();
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(R.layout.flow_save_item, null);
			view.mName = (TextView) convertView.findViewById(R.id.flow_save_name);
			view.mSize = (TextView) convertView.findViewById(R.id.flow_save_size);
			view.mState = (TextView) convertView.findViewById(R.id.flow_save_state);
			convertView.setTag(view);
		} else {
			view = (viewHode) convertView.getTag();
		}
		view.mState.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				cb.onClic(v, model);
			}
		});
		String size = model.size;
		if (!StringUtil.isNullOrEmpty(size)) {
			view.mSize.setText(size);
		}
		String name = model.name;
		if (!StringUtil.isNullOrEmpty(name)) {
			view.mName.setText(name);
		}
		String status = model.status;
		if (!StringUtil.isNullOrEmpty(status)) {
			view.mState.setText(status);
		}
		return convertView;
	}

	class viewHode {
		TextView mName;
		TextView mSize;
		TextView mState;
	}

	public interface CallBack {
		public void onClic(View view, FlowSaveModel model);
	}
}
